package com.hzz.dao.report;

import com.hzz.entity.report.ReportEvent;
import com.hzz.framework.dao.IBaseDao;
import com.hzz.framework.entity.IEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>事件上报 数据库处理接口类。
 */
@Mapper
public interface IReportEventDao extends IBaseDao {

    /**
      * 判断是否存在
      */
    @Override
    @Select("select IFNULL(count(0),0) as count from report_event where  id = #{id} ")
    int isDataExist(IEntity entity) throws Exception;

    /**
     * 逻辑删除
     */
    @Override
    @Update("update report_event set version=version+1, date_updated=now(), del_flag=1 where  id = #{id} ")
    int deleteById(IEntity entity) throws Exception;


    /**
     * 根据主键 物理删除
     */
    @Override
    @Delete("delete from report_event where  id = #{id} ")
    int deleteByPrimaryKey(IEntity entity) throws Exception;

    /**
     * 根据主键 时间关注
     */
    @Delete("update report_event set version=version+1, date_updated=now(), follow_state=1 where id = #{id} and follow_state = 0")
    int follow(IEntity entity) throws Exception;

    int finish(IEntity entity) throws Exception;

    /**
     * 更新同步结果
     */
    @Update("update report_event set dsync_state = #{dsyncState} ,dsync_count = dsync_count+1 ,dsync_djson = #{dsyncDjson} , dsync_result = #{dsyncResult} where  id = #{id} ")
    int updateDSync(IEntity entity) throws Exception;

    int dataStatistics(IEntity entity) throws Exception;

    List<ReportEvent> dataFailIsList(IEntity entity) throws Exception;
}